#
#   SEGA SATURN Graphic library make file for GNU

# macro
CC = gcc
AS = ../../awk/gasm_emx
LD = ld
RM = deltree
CONV = objcopy

# directory
SGLDIR = ../..
SGLIDR = $(SGLDIR)/inc
SGLLDR = $(SGLDIR)/lib

CMNDIR = ../common
OBJECTS = ./objects

# option
CCFLAGS = -O2 -m2 -g -c -I$(SGLIDR)
ASFLAGS =

# -m2 must be specified in LDFLAGS so the linker will search the SH2 lib dirs
# Specify path of libsgl.a by using "-L" option

LDFLAGS = -m2 -Xlinker -T$(LDFILE) -nostartfiles -Xlinker -Map \
          -Xlinker $(MPFILE) -nostdlib
          
DFLAGS =
# source_program
include $(OBJECTS)

TARGET   = ip.coff
TARGET1  = ip.bin
LDFILE	 = ip.lnk
MPFILE   = $(TARGET:.coff=.map)
MAKEFILE = Makefile

all: $(TARGET) $(TARGET1)

# Use gcc to link so it will automagically find correct libs directory

$(TARGET) : $(OBJS) $(MAKEFILE) $(OBJECTS) $(LDFILE)
	$(CC) $(LDFLAGS) $(OBJS) -o $@

$(TARGET1) : $(OBJS) $(MAKEFILE) $(LDFILE)
	$(CONV) -O binary $(TARGET) $(TARGET1)

# suffix
.SUFFIXES: .asm

%.o: %.c
#.c.o :
	$(CC) $< $(DFLAGS) $(CCFLAGS) -o $@

%.o: %.src
#.src.o :
	$(AS) $< $(ASFLAGS) $(_ASFLAGS) -o $@

clean:
	$(RM) $(CLEAN_OBJS) $(TARGET:.coff=.*)
